package com.csgc.camera.widget.mask

import android.content.Context
import android.graphics.Color
import android.util.TypedValue
import android.view.LayoutInflater
import android.view.View
import android.widget.TextView

import com.csgc.camera.constants.MaskConfig
import com.csgc.camera.storage.MaskPreference
import com.cysd.spsyxj.R


class MaskShengHuo :MaskBase {


    constructor(context: Context?,id:Int) : super(context,null){
        if (id == 0){
            LayoutInflater.from(context).inflate(R.layout.item_mask_sheng_huo_1, this, true)
        }else if(id == 1){
            LayoutInflater.from(context).inflate(R.layout.item_mask_sheng_huo_2, this, true)
        }else if(id == 2){
            LayoutInflater.from(context).inflate(R.layout.item_mask_sheng_huo_3, this, true)
        }else if(id == 3){
            LayoutInflater.from(context).inflate(R.layout.item_mask_sheng_huo_4, this, true)
        }else if(id == 4){
            LayoutInflater.from(context).inflate(R.layout.item_mask_sheng_huo_5, this, true)
        }

        dateStyle = "yyyy-MM-dd EEEE"
        if(MaskConfig.maskDateStyle.isNotEmpty()){
            dateStyle = MaskConfig.maskDateStyle
        }
        initView()
    }

    private fun initView(){
        location = findViewById(R.id.tv_sheng_huo_location)
        remark = findViewById(R.id.tv_sheng_huo_remark)
        date = findViewById(R.id.tv_sheng_huo_date)

        time = findViewById(R.id.tv_sheng_huo_time)
        customMaskContainer = findViewById(R.id.layout_custom_mask_container)

        location?.text = MaskConfig.maskLocation

        changeDateTime()
        val maskType = MaskPreference.instance.getMaskType()
//        MaskConfig.maskMap[0]?.forEach {
        MaskConfig.maskMap[maskType]?.forEach {
            if(it.title == "备注"){
                remark?.text = "${it.title}:${it.content}"
                remark?.visibility = if(it.isOpen) View.VISIBLE else View.GONE
            }
        }

        MaskConfig.customMaskInfo.forEach {
            val text = TextView(context)
            text.setTextColor(Color.WHITE)
            text.setTextSize(TypedValue.COMPLEX_UNIT_SP,14f)
            text.text = "${it.title}:${it.content}"
            text.visibility = if (it.isOpen) View.VISIBLE else View.GONE

            customMaskContainer?.addView(text)
        }

    }



}